home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 15 code / Symmetry & Tiles / Tiler Code / Shell Files / utils.c < prev   
Encoding:
C/C++ Source or Header  |  1994-05-27  |  3.4 KB  |  136 lines  |  [TEXT/KAHL]

  1. #include     "Shell.h"
  2.  
  3. extern  Boolean        doneflag;
  4.  
  5. /* These are stolen from arith.c, so we don't have to include the ANSI library */
  6. int
  7. abs(int i)
  8. {
  9.     if (i < 0)
  10.         return(-i);
  11.     return(i);
  12. }
  13.  
  14.  
  15. long
  16. labs(long i)
  17. {
  18.     if (i < 0)
  19.         return(-i);
  20.     return(i);
  21. }
  22.  
  23.  
  24. /****************************************************
  25. Quickdraw Things...
  26. *****************************************************/
  27.  
  28. /*------------------------------------------------------------------------
  29. NewPixImage()            Creates pix image and inits the fields of the pixmap...
  30. ------------------------------------------------------------------------*/
  31.  
  32. Boolean NewPixImage(PixMapHandle ThePix, Rect *TheRect, short dpth)
  33. {
  34.     Ptr                    ThePtr;
  35.     long                Offrowbytes, ptrsize;
  36.     
  37.     Offrowbytes    =(((dpth * (TheRect->right - TheRect->left)) + 15) / 16) * 2;
  38.     ptrsize = (TheRect->bottom - TheRect->top) * Offrowbytes;
  39.     ThePtr = NewPtr(ptrsize);
  40.     if(MemError() != noErr)
  41.         return(false);
  42.     
  43.     (**ThePix).baseAddr = ThePtr;
  44.     (**ThePix).rowBytes = Offrowbytes + 0x8000;
  45.     (**ThePix).bounds = *TheRect;
  46.     (**ThePix).pixelSize = dpth;
  47.     (**ThePix).cmpCount = 1;
  48.     (**ThePix).cmpSize = dpth;
  49.     return(true);
  50. }
  51.     
  52.  
  53. /*------------------------------------------------------------------------
  54. NewBitMap()            Creates bit image and inits the fields of the bitmap...
  55.  
  56. Boolean NewBitMap(BitMap *TheMap, Rect *TheRect)
  57. {
  58.     long    rb;
  59.     Ptr        ba;
  60.     
  61.     rb = ((TheRect->right - TheRect->left + 15) / 16) * 2;
  62.     ba = NewPtr(rb * (TheRect->bottom - TheRect->top));
  63.     if( MemError() == noErr)
  64.     {
  65.         TheMap->rowBytes = rb;
  66.         TheMap->baseAddr = ba;
  67.         TheMap->bounds = *TheRect;
  68.         return(true);
  69.     }
  70.     else
  71.         return(false);
  72. }
  73. ------------------------------------------------------------------------*/
  74.  
  75.  
  76. /*-------------------------------------------------------------------------
  77. CenterRect()             Centers theRect over thePt...
  78. --------------------------------------------------------------------------*/
  79. void CenterRect(Rect *theRect, Point *thePt)
  80. {
  81.     /* First home theRect... */
  82.     
  83.     OffsetRect(theRect, -theRect->left, -theRect->top);
  84.     
  85.     /* ...then center it over thePt */
  86.     
  87.      
  88.     thePt->h = thePt->h - (theRect->right / 2);
  89.     thePt->v = thePt->v - (theRect->bottom / 2);
  90.     OffsetRect(theRect, thePt->h, thePt->v);
  91. }
  92.  
  93. /*-------------------------------------------------------------------------
  94. Center()             Returns the center of the rect
  95. --------------------------------------------------------------------------*/
  96. Point Center(Rect *theRect)
  97. {
  98.     Point        pt;
  99.         
  100.     pt.h = theRect->left + ((theRect->right - theRect->left) / 2);
  101.     pt.v = theRect->top + ((theRect->bottom - theRect->top) / 2);
  102.     return(pt);
  103. }
  104.  
  105.  
  106. /*-------------------------------------------------------------------------
  107. These routines are from DTS Utilities
  108. --------------------------------------------------------------------------*/
  109. short    NumToolboxTraps(void)
  110. {
  111.     if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap))
  112.         return (0x200);
  113.     else
  114.         return (0x400);
  115. }
  116.  
  117. TrapType    GetTrapType(short theTrap)
  118. {
  119.     /* OS traps start with A0, Tool with A8 or AA. */
  120.     if ((theTrap & 0x0800) == 0)                    /* per D.A. */
  121.         return (OSTrap);
  122.     else
  123.         return (ToolTrap);
  124. }
  125.  
  126. Boolean TrapAvailable(short theTrap)
  127. {
  128.     TrapType    theTrapType;
  129.  
  130.     theTrapType = GetTrapType(theTrap);
  131.     if ((theTrapType == ToolTrap) && ((theTrap &= 0x07FF) >= NumToolboxTraps()))
  132.         theTrap = _Unimplemented;
  133.  
  134.     return (NGetTrapAddress(_Unimplemented, ToolTrap) != NGetTrapAddress(theTrap,
  135.                   theTrapType));
  136. }